package web.exception;

import java.util.Map;

import javax.faces.context.FacesContext;

import org.springframework.stereotype.Controller;

@Controller
public class ErrorMBean {
	 private static final String BR = "n";

	   public String getStackTrace()
	   {
	       FacesContext context = FacesContext.getCurrentInstance();
	       Map<String,Object> map = context.getExternalContext().getRequestMap();
	       Throwable throwable = (Throwable) map.get("javax.servlet.error.exception");
	       StringBuilder builder = new StringBuilder();
	       builder.append(throwable.getMessage()).append(BR);

	       for (StackTraceElement element : throwable.getStackTrace())
	       {
	         builder.append(element).append(BR);
	       }

	       return builder.toString();
	   }
}
